import 'package:flutter/material.dart';
import 'package:get/get.dart';

class AnimPage extends StatefulWidget {
  const AnimPage({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _LogoAppState();
}

class _LogoAppState extends State<AnimPage> with SingleTickerProviderStateMixin {
  bool isPlaying = false;

  Animation? animation;

  AnimationController? controller;

  @override
  void initState() {
    super.initState();

    controller = AnimationController(duration: const Duration(milliseconds: 500), vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: const Text("动画效果"),
          leading: BackButton(
            onPressed: () {
              Get.back();
            },
          ),
        ),
        body: ListView(
          children: [
            IconButton(
              iconSize: 70,
              icon: AnimatedIcon(
                icon: AnimatedIcons.add_event,
                progress: controller!,
              ),
              onPressed: () => _onpressed(),
            ),
            const Text("点击一下")
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    controller?.dispose();
    super.dispose();
  }

  _onpressed() {
    setState(() {
      isPlaying = !isPlaying;
      isPlaying ? controller?.forward() : controller?.reverse();
    });
  }
}
